package com.dapeis.web.wx.service;

import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpServiceImpl;

import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;
import com.ag.spring.event.CommonEvent;
import com.ag.utils.SysConstant;
import com.ag.utils.TypeConvertUtils;
import com.dapeis.pay.wxpay.config.WXpayConfig;

/**
 * 
 * Title:StylistWxMpServiceImpl.java StylistWxMpServiceImpl Description:
 * @author yuanyong
 * @date 2017年4月18日 上午9:36:56 Email: hzyuanyong@126.com
 *
 */
@Service
public class StylistWxMpServiceImpl extends WxMpServiceImpl implements
	ApplicationListener<CommonEvent> {
    @Override
    public void onApplicationEvent(CommonEvent event) {
	if (SysConstant.SysCmd.INIT.equals(event.getCmd())) {
	    try {
		WxMpInMemoryConfigStorage wxMpConfigStorage = TypeConvertUtils
			.fromProperties(WxMpInMemoryConfigStorage.class, "wx.");
		// 保持统一
		WXpayConfig.api_key = wxMpConfigStorage.getPartnerKey();
		WXpayConfig.appid = wxMpConfigStorage.getAppId();
		WXpayConfig.mch_id = wxMpConfigStorage.getPartnerId();
		//System.out.println("---------- app_key  ---------- : "+ wxMpConfigStorage.getPartnerKey());
		//System.out.println("---------- appid  ---------- : "+ wxMpConfigStorage.getAppId());
		this.setWxMpConfigStorage(wxMpConfigStorage);
	    } catch (InstantiationException | IllegalAccessException e) {
		e.printStackTrace();
	    }
	}
    }
}